/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Jov
 */
@Entity
@Table(name = "participants")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Participants.findAll", query = "SELECT p FROM Participants p"),
    @NamedQuery(name = "Participants.findByEventId", query = "SELECT p FROM Participants p WHERE p.participantsPK.eventId = :eventId"),
    @NamedQuery(name = "Participants.findByEventIdAndParticipantId", query = "SELECT p FROM Participants p WHERE p.participantsPK.eventId = :eventId AND p.participantsPK.participantId = :participantId"),
    @NamedQuery(name = "Participants.findByParticipantId", query = "SELECT p FROM Participants p WHERE p.participantsPK.participantId = :participantId")})
public class Participants implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ParticipantsPK participantsPK;
    @JoinColumn(name = "invitation_id", referencedColumnName = "invitation_id")
    @ManyToOne(optional = false)
    private Invitations invitationId;
    @JoinColumn(name = "participant_id", referencedColumnName = "user_id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Users users;
    @JoinColumn(name = "event_id", referencedColumnName = "event_id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Events events;

    public Participants() {
    }

    public Participants(ParticipantsPK participantsPK) {
        this.participantsPK = participantsPK;
    }

    public Participants(int eventId, int participantId) {
        this.participantsPK = new ParticipantsPK(eventId, participantId);
    }

    public ParticipantsPK getParticipantsPK() {
        return participantsPK;
    }

    public void setParticipantsPK(ParticipantsPK participantsPK) {
        this.participantsPK = participantsPK;
    }

    public Invitations getInvitationId() {
        return invitationId;
    }

    public void setInvitationId(Invitations invitationId) {
        this.invitationId = invitationId;
    }

    public Users getUsers() {
        return users;
    }

    public void setUsers(Users users) {
        this.users = users;
    }

    public Events getEvents() {
        return events;
    }

    public void setEvents(Events events) {
        this.events = events;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (participantsPK != null ? participantsPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Participants)) {
            return false;
        }
        Participants other = (Participants) object;
        if ((this.participantsPK == null && other.participantsPK != null) || (this.participantsPK != null && !this.participantsPK.equals(other.participantsPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Participants[ participantsPK=" + participantsPK + " ]";
    }
    
}
